﻿using DtRlDeviceApiNet20;
using DtRlDeviceApiNet20.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Serialization;

namespace App.Sdx.Api
{
    public partial class Upload : System.Web.UI.Page
    {
        private ApiWebClientInterface _apiClientInterface = new ApiWebClientInterface();
        static string Url = ConfigurationManager.AppSettings["WriteTrainSamplingData"].ToString();
        static string SimplingCode = ConfigurationManager.AppSettings["SimplingCode"].ToString();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["upStr"] != null)
            {
                var josnString = Request.QueryString["upStr"].ToString();
                Response.Write(josnString);
                
            }
            TrainSamplingData trdata = new TrainSamplingData();
            ReturnMsg returnMsg = this._apiClientInterface.WriteTrainSamplingData(Url, trdata);
            if (this._apiClientInterface.ErrorCode != 0)
            {
                LogHelper.DoErrorWrite("采样上传数据失败:  " + this._apiClientInterface.ErrorText);
                var serializer = new XmlSerializer(typeof(TrainSamplingData));
                using (var stringWriter = new StringWriter())
                {
                    LogHelper.DoErrorWrite("采样上传数据失败:  " + this._apiClientInterface.ErrorText);
                    serializer.Serialize(stringWriter, trdata);
                    string xmlString = stringWriter.ToString();
                    LogHelper.DoErrorWrite("采样上传数据失败:  " + xmlString);
                }
                 
            }
            else if (returnMsg.Result == "OK")
            {

                LogHelper.DoErrorWrite("采样上传数据成功");
            }
            else
            {
                LogHelper.DoErrorWrite("采样上传数据失败:  " + returnMsg.Result);
            }
        }
    }
}